<?php
/**
 * WpSimpleSession.php
 * 
 * This file contains the class WpSimpleSession, just a wrapper for $_SESSION
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage web
 */

/**
 * The interface to implement
 */
require_once (dirname(__FILE__).'/IWpSession.php');

/**
 * This class is a wrapper for $_SESSION
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage web
 */
class WpSimpleSession implements IWpSession
{
	/**
   * Starts a new session or loads a session specified by id
   * @param string $id [optional] The session id. To set the timeout 
   * parameter without specifying an id, provide an empty string
   * @param int $timeout [optional] The session timeout in seconds (default is 300)  
   */
	public function startSession($id = '', $timeout = 300)
	{
		@session_start();
	}
	
	/**
   * Closes a session and throws all session variables away
   * @param string $id [optional] The if of the session
   */
	public function endSession($id = '')
	{
		@session_destroy();
	}
	
	/**
   * Sets a session variable
   * @param string $name The name of the session variable to set
   * @param mixed $value The value to set the session variable to
   * @return True if successfully set false else (if no session is started, it returns false) 
   */
	public function set($name, $value)
	{
		if (!is_array($_SESSION)) {
			return false;
		}
		
		$_SESSION[$name] = $value;
		return true;
	}
	
	/**
   * Retrieves the value of a session variable
   * @param string $name The name of the variable to return
   * @return mixed The variables value
   */
	public function get($name)
	{
		if (!is_array($_SESSION) || !array_key_exists($name, $_SESSION)) {
			return null;
		}
		
		return $_SESSION[$name];
	}
}

/* End of file WpSimpleSession.php */
/* Location: ./wildpack/web/WpSimpleSession.php */ 
